package com.category.douyijia.services;

import java.util.ArrayList;
import java.util.List;

import com.category.douyijia.base.BaseService;
import com.category.douyijia.model.OrdMang;
import com.category.douyijia.model.OrdMaster;

/**
 * 创建的类继承基础类 ，实现增删改查功能
 * 基础类里利用的是键值对
 * @author jiangmengyang
 * @version v1.0
 * date time 2021年7月19日10:35:47
 */
public class OrdMasterService extends BaseService<OrdMasterService, OrdMaster> {
	/**
	 * 创建一个空对象
	 * 修改数据时往里面传值
	 * 只能传一个值
	 */
	private OrdMaster ordMaster = null;
	/**
	 * 订单主表集合里面的实体类
	 */
	private OrdMaster ordMasters = null;
	/**
	 * 建立一个DAO模板
	 * 写增删改查功能时更简便
	 * 利用的是jfinal的方法
	 * 使数据更简便
	 */
	public static OrdMaster ordMasterDao = (OrdMaster)new OrdMaster().dao();
	/**
	    *将OrdMang的对象添加到数据库
	    * @param ordMang
	    * *ordMang为数据表的一个参数
	    *参数里有值包括列名
	    * @return
	    * 如果ordMang 不为空添加数据库成功
	    * 如果ordMang为空添加不了数据库
	    */
 public boolean put(OrdMaster ordMaster) {
	   if(ordMaster!=null && !(ordMaster.equals(""))) {
		   return ordMaster.save();
	   }else {
		   System.out.println("参数为空！");
		   return false;
	   }
}
 /**
  * 查询表里的全部数据
  * 建一个ArrayList包
  * @return
  *返回的是所有的信息
  *
  */
 public List<OrdMaster> findAll() {
 	return (ArrayList)ordMasterDao.findAll();
 }
 /**
  * 这是通过订单编号查询订单主表里的数据
  * @param ordMasterId
  * 通过ordMasterId查找订单主表里的全部信息
  * @return
  * ordMasterId如果不为空的话就返回，
  * 订单主表里的所查找的那些列
  * ordMasterId如果为空的话，
  * 返回的结果是一个空值
  */
 public OrdMaster findByOrdMasterId(String ordMasterId){
 	if(ordMasterId!=null && !(ordMasterId.equals(""))) {
 		return (OrdMaster) this.ordMaster.find(
 				"select ord_master_id,ord_state,total_money,pay_state,"
 				+ "turnover_time,creation_time,"
 				+ "buyer_site,buyer_tel,buyer_name,delete_state"
 				+ " from OrdMaster "
 				+ "where ord_master_id "
 				+ "= ? ", ordMasterId);	
 	}else {
 		return null;
 	}
 }
 /**
  * 通过支付状态查询，
  * 订单主表里的所有数据
  * @param payState
  * @return
  * payState如果不为空的话就返回，
  * 订单主表里的所查找的那些列
  * payState如果为空的话，
  * 返回的结果是一个空值
  */
 public List<OrdMaster> findByPayState(String  payState){
 	if(payState!=null && !(payState.equals(""))) {
 		return (ArrayList)ordMaster.find(
 				"select ord_master_id,ord_state,total_money,pay_state,"
 		 				+ "turnover_time,creation_time,"
 		 				+ "buyer_site,buyer_tel,buyer_name,delete_state"
 		 				+ " from OrdMaster "
 		 				+ "where pay_state "
 		 				+ "= ? ", payState);	
 	}else {
 		return null;
 	}
 }
 /**
  * 通过创建时间查询，
  * 订单主表里的所有数据
  * @param creationTime
  * @return
  * creationTime如果不为空的话就返回，
  * 订单主表里的所查找的那些列
  * creationTime如果为空的话，
  * 返回的结果是一个空值
  */
 public List<OrdMaster> findByCreationTime(String  creationTime){
 	if(creationTime!=null && !(creationTime.equals(""))) {
 		return (ArrayList)ordMaster.find(
 				"select ord_master_id,ord_state,total_money,pay_state,"
 		 				+ "turnover_time,creation_time,"
 		 				+ "buyer_site,buyer_tel,buyer_name,delete_state"
 		 				+ " from OrdMaster "
 		 				+ "where creation_time "
 		 				+ "= ? ", creationTime);	
 	}else {
 		return null;
 	}
 }
 /**
  * 通过买家地址查询，
  * 订单主表里的所有数据
  * @param  buyerSite
  * @return
  *  buyerSite如果不为空的话就返回，
  * 订单主表里的所查找的那些列
  *  buyerSite如果为空的话，
  * 返回的结果是一个空值
  */
 public List<OrdMaster> findByBuyerSite(String buyerSite){
 	if( buyerSite!=null && !( buyerSite.equals(""))) {
 		return (ArrayList)ordMaster.find(
 				"select ord_master_id,ord_state,total_money,pay_state,"
 		 				+ "turnover_time,creation_time,"
 		 				+ "buyer_site,buyer_tel,buyer_name,delete_state"
 		 				+ " from OrdMaster "
 		 				+ "where buyer_site"
 		 				+ "= ? ",  buyerSite);	
 	}else {
 		return null;
 	}
 }
 /**
  * 通过买家电话查询，
  * 订单主表里的所有数据
  * @param  buyerTel
  * @return
  * buyerTel如果不为空的话就返回，
  * 订单主表里的所查找的那些列
  *  buyerTel如果为空的话，
  * 返回的结果是一个空值
  */
 public List<OrdMaster> findByBuyerTel(String buyerTel){
 	if( buyerTel!=null && !( buyerTel.equals(""))) {
 		return (ArrayList)ordMaster.find(
 				"select ord_master_id,ord_state,total_money,pay_state,"
 		 				+ "turnover_time,creation_time,"
 		 				+ "buyer_site,buyer_tel,buyer_name,delete_state"
 		 				+ " from OrdMaster "
 		 				+ "where buyer_tel"
 		 				+ "= ? ",  buyerTel);	
 	}else {
 		return null;
 	}
 }
 /**
  * 通过买家名称查询，
  * 订单主表里的所有数据
  * @param  buyerName
  * @return
  * buyerName如果不为空的话就返回，
  * 订单主表里的所查找的那些列
  *  buyerName如果为空的话，
  * 返回的结果是一个空值
  */
 public List<OrdMaster> findByBuyerName(String buyerName){
 	if( buyerName!=null && !( buyerName.equals(""))) {
 		return (ArrayList)ordMaster.find(
 				"select "
 				        + "ord_master_id,ord_state,total_money,pay_state,"
 		 				+ "turnover_time,creation_time,"
 		 				+ "buyer_site,buyer_tel,buyer_name,delete_state"
 		 				+ " from OrdMaster "
 		 				+ "where buyer_name"
 		 				+ "= ? ",  buyerName);	
 	}else {
 		return null;
 	}
 }
 /**
  * 通过ordMasterId删除数据库里的数据
  * 先查询数据库 里的全部数据，
  * 再进行更改数据
  * @param ordMasterId
  * @return
  * 返回更改后的数据
  */
    public boolean deleteByOrdMasterId(String ordMasterId) {
    	ordMaster = findByOrdMasterId(ordMasterId);
    	return ordMaster.dao().set("deleteState", 0).update();
    }
}
